
function SetAllCameraDefault(a)
{
	flashpoint();

	printf('# SetCameraDefault()');
	printf('# sets user default to factory setting');
	printf('# sets current  to factory setting');

	var usetVar=new Array("uset0","uset1","uset2","uset3","uset4","uset5","uset6","uset7" );
	var isetVar=new Array("iset0","iset1","iset2","iset3","iset4","iset5","iset6","iset7" );
	var ssetVar=new Array("sset0","sset1","sset2","sset3","sset4","sset5","sset6","sset7" );
	
	var setTitle=new Array("title0","title1","title2","title3","title4","title5","title6","title7" );

	var i,setting;
	
	writeMenu('"SetAllCameraDefault"','"CMD"','"SetAllCameraDefault()"');
	writeVariables();
	printf('declare s: readwrite ');

	print('declare u: uset0');
	for(i=1 ;i< usetVar.length ; i++) print(",",usetVar[i]); printf(' ');
	print('declare i: iset0');
	for(i=1 ;i< isetVar.length ; i++) print(",",isetVar[i]); printf(' ');
	print('declare s: sset0');
	for(i=1 ;i< ssetVar.length ; i++) print(",",ssetVar[i]); printf(' ');

	print('declare s: title0');	
	for(i=1 ;i< setTitle.length ; i++) print(",",setTitle[i]); printf(' ');

	printf('declare u: doit,countSetting,factorycurrent');
	printf('declare u: udummy, uuser, ufactory , ucurrent');
	printf('declare i: idummy, iuser, ifactory , icurrent');
	printf('declare s: sdummy, suser, sfactory , scurrent');
	printf('declare b: bdummy, buser, bfactory , bcurrent');
	
	
	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZSADef.txt"');
	writeFileOpen();


	printf('WriteLine(fd," ")');
	printf('WriteLine(fd," SetAllCameraDefault()")');
	printf('WriteLine(fd," sets user default to current setting")');
	printf('WriteLine(fd," sets current to factory setting")');

		printf('count=1');
		printf('LOOP:');
		printf('doit=0');
		printf('theType="UInt"');

		printf('countSetting=0');
		printf('RestoreCameraDefault(0,"")')
		
		
		for( i=1 ; i< a.length ; i++)
		{ 			

 		// only can change a RW parameter 
  		if( a[i].host != "Write" ){
 				printf(" ");
 				printf('if count == ',i );
 				printf('WriteLine(fd," ")' );
				printf('WriteLine(fd,"**** ',a[i].desc,' ****" )' );
 				printf('WriteLine(fd,count,','")",',a[i].param,'," is READ only *************" )' );
 				printf('end');
 		 		continue;
 		}	
 			
 	 			printf(" ");
 				printf('if count == ', i );
  	 			printf("doit=1");
  	 			printf('param=',a[i].param);
  	 			printf(setTitle[0],'="',a[i].desc,'"');
  	 			
  	 			// write theType									
				
		}// end of this HUGE for loop
		printf(' ');
		
// start to examine SetCameraDefault()
	printf('Wait(100)');
	printf('if doit == 0');
	printf('count=count+1 ');	
	printf('goto LOOP');
	printf('end');
	printf(' ');
	
	printf('WriteLine(fd," ")' );
	printf('WriteLine(fd,"**** ",',setTitle[0],'," ****" )' );

 	printf(' if theType=="SInt"');
 	printf(' goto case_SINT');
 	printf(' end','<br>');

 	printf(' if theType=="String"');
 	printf(' goto case_STRING');
 	printf(' end','<br>');
	
	printf(' ' );
	printf('CASE_UINT:');
	// set user default to factory state
	
	printf('# user default = current state ');
	printf('status = GetCameraDefault(0,param,ucurrent)');
	printf('status1= SetCameraState(param,ucurrent)' );
	printf('status2= SetCameraDefault(0,param,ucurrent)' );

	printf('if theType != "Hex" ');
	printf('DisplayLine(count,")",param,"[",status,"] " , uuser )' );
	printf('Write(fd,count,")",param,"[",status,"][",status1,"][",status2,"] ")' );
	printf('WriteLine(fd,ucurrent," default)" )' );	
	printf('end','<br>');
	
	printf('if theType == "Hex" ');
	printf('bcurrent=ucurrent');
	printf('DisplayLine(count,")",param,"[",status,"] " , buser )' );
	printf('Write(fd,count,")",param,"[",status,"][",status1,"][",status2,"] ")' );
	printf('WriteLine(fd,bcurrent," ( default)" )' );	
	printf('end','<br>');
	
	
	printf('case_SINT:');

	// set user default to current state	
	printf('# user default = current state ');
	printf('status2=GetCameraDefault(1,param,icurrent)' );	
	printf('status = SetCameraState(0,param,icurrent)');
	printf('status1=SetCameraDefault(1,param,idummy)' );

	printf('DisplayLine(count,")",param,"[",status,"] " , ivar2 )' );
	printf('Write(fd,count,")",param,"[",status,"][",status1,"][",status2,"] ")' );
	printf('WriteLine(fd,uvar," (current) ",ivar2," (default) " )' );	
		
	printf('<br>','if icurrent != iuser');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');		
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');

	// set user default to factory default 
	printf('# user default = factory default ');
	printf('status1= SetCameraDefault(0,param,idummy)' );
	printf('status = GetCameraDefault(0,param,ifactory)');
	printf('status2= GetCameraDefault(1,param,iuser)' );

	printf('DisplayLine(count,")",param,"[",status,"] " , iuser )' );
	printf('Write(fd,count,")",param,"[",status,"][",status1,"][",status2,"] ")' );
	printf('WriteLine(fd,iuser," (user) ",ifactory," (factory)" )' );	
		
	printf('<br>','if iuser != ifactory');
	printf(' DisplayLine(" *** ??? ERROR ??? *** ") ');		
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ") ');
	printf(' end ','<br>');


	
	printf('goto CONTINUE');

	printf('# SINT finished  ***************************************************');		

	printf('case_STRING:');	
	printf('# user default = current state ');
	printf('status = GetCameraState(param,svar)');
	printf('status1=SetCameraDefault(1,param,sdummy)' );
	printf('status2=GetCameraDefault(1,param,svar2)' );
		
	printf('DisplayLine(count,")",param,"[",status,"] " , svar2 )' );
	printf('Write(fd,count,")",param,"[",status,"][",status1,"][",status2,"] ")' );
	printf('WriteLine(fd,svar," (current) ",svar2," (default)" )' );	

//# **********CUT HERE ****************************************************
	for( n=1 ; n<=ssetVar.length-1 ; n++){
			
	printf(' if countSetting>=',n);
	printf(' status=SetCameraDefault(2,param,',ssetVar[n],')');
	printf(' status1=GetCameraDefault(1,param,svar)  ');

	printf(' DisplayLine(count,")",param,"[",status,"] " ,', ssetVar[n] ,'," (",',setTitle[n],',")" ) ');
	printf(' WriteLine(fd,count,")",param,"[",status,"] " ,', ssetVar[n] ,'," (",',setTitle[n],',") (", svar,")") ');

	printf(' if ',ssetVar[n],'!= svar');
	printf(' WriteLine(fd," *** ??? ERROR ??? *** ")  ');
	printf(' end  ');
	printf(' end <br>');
	
	}

//# **********CUT HERE ****************************************************
		
	printf('# STRING finished  ************************************************');		


	printf('CONTINUE:');
	printf(' ');
	printf('if count<', a.length-1 );
	printf('count=count+1 ');
	printf('goto LOOP');
	printf('end');
	
	printf('# RESTORE USER DEFAULTS to FACTORY DEFAULTS ');
	printf('RestoreCameraDefault(0,"")');
	printf('# ');
	
	
	writeFileClose();
	printf('exitscript');

}

